package cc.wubo.jpa.config;

import javax.persistence.EntityManager;
import javax.persistence.LockModeType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cc.wubo.jpa.entity.User;

@Service
public class UserService {
	@Autowired
	private EntityManager em;

	@Transactional
	public void lock(){
		User user=em.find(User.class, 1,LockModeType.OPTIMISTIC_FORCE_INCREMENT);
		System.out.println(user);
		user.setName("wangwu");
		em.merge(user);
		
	}
}
